package com.smedi.ismedi.notification.core.port.adapter.restful;

import com.smedi.ismedi.notification.api.dto.request.SendSmsRequest;
import com.smedi.ismedi.notification.api.feign.RemoteSmsNotificationFeignApi;
import com.smedi.ismedi.notification.core.application.command.SendSmsCommand;
import com.smedi.ismedi.notification.core.application.service.SmsNotificationApplicationService;
import com.smedi.ismedi.notification.core.domain.service.SmsTemplateDomainService;
import com.smedi.ismedi.notification.core.infrastructure.constant.CustomError;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.exception.LogicException;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xulinjun
 * @Date: 2021-7-12 13:43
 */
@Slf4j
@RestController
@AllArgsConstructor
public class SmsNotificationController implements RemoteSmsNotificationFeignApi {
    private final DozerUtil dozerUtil;

    private final SmsNotificationApplicationService smsNotificationApplicationService;

    /**
     * {@inheritDoc}
     */
    @Override
    public ResponseData<Boolean> postSendShortMessage(SendSmsRequest sendSmsRequest) {
        SendSmsCommand sendSmsCommand = dozerUtil.convertor(sendSmsRequest, SendSmsCommand.class);
        smsNotificationApplicationService.sendShortMessage(sendSmsCommand);

        return new ResponseData<Boolean>().success(true);
    }

    @Override
    public ResponseData<Boolean> postSendShortMessage(List<SendSmsRequest> sendSmsRequests) {
        for(SendSmsRequest sendSmsRequest:sendSmsRequests){
            this.postSendShortMessage(sendSmsRequest);
        }
        return new ResponseData<Boolean>().success(true);
    }
}
